﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Palsta.Core.data
{
    class IntegerField : Field
    {
        private int value;

        public IntegerField(int v)
        {
            this.value = v;
        }
        override public String GetStringValue()
        {
            return "" + value;
        }

        override public Boolean SetValue(String v)
        {
            this.value = Int32.Parse(v);
            return true;
        }

        override public FieldType GetFieldType()
        {
            return FieldType.Integer;
        }

        override public Boolean Equels(Field f)
        {
            if (f.GetFieldType() == FieldType.Boolean)
            {
                return false;
            }
            else if (f.GetFieldType() == FieldType.String)
            {
                return false;
            }
            else if (f.GetFieldType() == FieldType.Integer)
            {
                return this.value == ((IntegerField)f).value;
            }
            return false;
        }

        override public Boolean NotEquels(Field f)
        {
            return !this.Equals(f);
        }


        override public Field Add(Field f)
        {
            if (f.GetFieldType() == FieldType.Integer)
            {
                return new IntegerField(this.value + ((IntegerField)f).value);
            }
            else
            {
                return this;
            }
        }
    }
}
